<template>
  <div class="container">
    <div class="register-form">
      <h2>用户注册</h2>
      <form @submit.prevent="registerUser" enctype="multipart/form-data">
        <div class="form-group">
          <label for="avatar">上传头像:</label>
          <input type="file" id="avatar" accept="image/*" @change="handleAvatarChange">
        </div>
        <div class="form-group">
          <label for="nickname">昵称:</label>
          <input type="text" id="nickname" v-model="userData.nickname" required>
        </div>
        <div class="form-group">
          <label for="password">密码:</label>
          <input type="password" id="password" v-model="userData.password" required>
        </div>
        <div class="form-group">
          <label for="confirmPassword">确认密码:</label>
          <input type="password" id="confirmPassword" v-model="confirmPassword" required>
        </div>
        <div class="form-group">
          <label for="fullName">姓名:</label>
          <input type="text" id="fullName" v-model="userData.fullName" required>
        </div>
        <div class="form-group">
          <label for="gender">性别:</label>
          <select id="gender" v-model="userData.gender" required>
            <option value="">请选择性别</option>
            <option value="male">男</option>
            <option value="female">女</option>
          </select>
        </div>
        <div class="form-group">
          <label for="phoneNumber">手机号:</label>
          <input type="tel" id="phoneNumber" v-model="userData.phoneNumber" required>
        </div>
        <button type="submit" class="btn btn-primary">注册</button>
        <button type="button" @click="resetForm" class="btn btn-secondary">重置</button>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userData: {
        avatar: null,
        nickname: '',
        password: '',
        fullName: '',
        gender: '',
        phoneNumber: ''
      },
      confirmPassword: ''
    };
  },
  methods: {
    registerUser() {
      // 模拟注册成功，并保存用户信息到数据库
      // 这里应该发送 HTTP 请求将用户信息保存到数据库
      console.log('模拟注册成功，用户信息:', this.userData);
      // 页面跳转到个人信息页面
      this.$router.push({ name: 'UserInfo', params: { userData: this.userData } });
    },
    handleAvatarChange(event) {
      this.userData.avatar = event.target.files[0];
    },
    resetForm() {
      // 清空表单数据
      this.userData = {
        avatar: null,
        nickname: '',
        password: '',
        fullName: '',
        gender: '',
        phoneNumber: ''
      };
      this.confirmPassword = '';
    }
  }
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.register-form {
  width: 400px;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
  margin-bottom: 20px;
  font-size: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
}

.btn-primary {
  background-color: #007bff;
  color: #fff;
}

.btn-secondary {
  background-color: #6c757d;
  color: #fff;
}
</style>

